<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\Live;
use Illuminate\Http\Request;

class LiveController extends Controller
{
    public function push(Request $request)
    {

    }

    public function pull(Request $request)
    {

    }

    public function count(Request $request)
    {

    }

    /**
     * 直播列表展示
     */
    public function liveList()
    {
        try {
            $result = Live::liveList();
            return success('数据查询成功', $result);
        } catch (\Exception $exception) {
            return fails($exception->getMessage(), '');
        }
    }

    /**
     * 直播添加
     * @param Request $request
     * @return array
     */
    public function addLive(Request $request)
    {
        $postData = $request->post();

        //组装数据
        $arr = [
            'title' => $postData['title'],
            'content' => $postData['content'],
            'cover' => $postData['cover'],
            'model' => '横屏直播',
            'goods_id' => $postData['goods_id'],
            'author' => $postData['author'],
            'state' => 1,
            'uid' => 1,
            'pull_url' => 'http://live.wyt.plus/live/wyt.flv',
            'start_time' => date('Y-m-d H:i:s'),
        ];

        try {
            $result = Live::addLive($arr);
            return success('数据添加成功', $result);
        } catch (\Exception $exception) {
            return fails($exception->getMessage(), '');
        }

    }

}
